package ListDemo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> List = new ArrayList<>();
        List.add(1);
        List.add(2);
        List.add(3);
        List.add(4);

        System.out.println("============for循环============");
        for (int i = 0; i < List.size(); i++) {
            System.out.print(List.get(i) + " ");
        }
        System.out.println();

        System.out.println("============for each循环============");
        for (Integer x : List) {
            System.out.print(x + " ");
        }
        System.out.println();

        System.out.println("============迭代器循环1============");
        Iterator<Integer> it = List.iterator();
        while(it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();

        System.out.println("============迭代器循环2============");
        ListIterator<Integer> list = List.listIterator();
        while(list.hasNext()){
            System.out.print(list.next() + " ");
        }
        System.out.println();

        System.out.println("============迭代器循环3============");
        ListIterator<Integer> listPrev = List.listIterator(List.size());
        while(listPrev.hasPrevious()){
            System.out.print(listPrev.previous() + " ");
        }
        System.out.println();
    }

    public static void main1(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);

        myArrayList.add(2,17);
        myArrayList.display();
        myArrayList.remove(6);
        myArrayList.display();
        System.out.println(myArrayList.usedSize);

    }
}
